package com.guldan.jaina.provider;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.guldan.core.dubbo.client.ResponseDTO;
import com.guldan.core.search.Pagination;
import com.guldan.jaina.dto.organization.OrganizationDTO;
import com.guldan.jaina.dto.organization.OrganizationSearchDTO;
import com.guldan.jaina.manager.OrganizationManager;

/**
 * Created by Silas.
 * Date: 2016/11/7
 * Time: 22:54
 */
@Component
public class OrganizationProviderImpl implements IOrganizationProvider {

    @Autowired
    private OrganizationManager organizationManager;

    @Override
    public ResponseDTO<OrganizationDTO> get(Integer areaId) {
        ResponseDTO<OrganizationDTO> response = new ResponseDTO<>();
        response.setData(organizationManager.get(areaId));
        return response;
    }

    @Override
    public ResponseDTO<OrganizationDTO> save(OrganizationDTO dto) {
        ResponseDTO<OrganizationDTO> response = new ResponseDTO<>();

        try {
            response.setData(organizationManager.save(dto));
        } catch (Exception ex) {
            response.setStatus(false);
            response.setException(ex);
        }
        return response;
    }

    @Override
    public ResponseDTO<Boolean> delete(Integer areaId) {
        ResponseDTO<Boolean> response = new ResponseDTO<>();
        response.setData(organizationManager.delete(areaId));
        return response;
    }

    @Override
    public ResponseDTO<Pagination<OrganizationDTO>> list(OrganizationSearchDTO areaSearchDTO) {
        ResponseDTO<Pagination<OrganizationDTO>> response = new ResponseDTO<>();
        response.setData(organizationManager.list(areaSearchDTO));
        return response;
    }

	@Override
	public ResponseDTO<Boolean> batchImport(List<OrganizationDTO> list) {
        ResponseDTO<Boolean> response = new ResponseDTO<>();
        response.setData(organizationManager.batchImport(list));
        return response;
	}

}
